/**
 *  Copyright 2002-2009 the original author or authors.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package foo.bar.blog.radeox;

import foo.bar.blog.core.domain.*;
import foo.bar.radeox.api.engine.RenderEngine;
import foo.bar.radeox.engine.context.BaseRenderContext;

import java.util.Date;
import java.util.LinkedHashMap;

/**
 * Decorates a {@link Comment} object by providing {@link #getDecoratedContent()} which is a
 * {@link RenderEngine} decorated content of {@link foo.bar.blog.core.domain.Comment}'s content.
 *
 * @see {@link foo.bar.blog.radeox.DecoratedEntryTransformer}
 *
 * @author tmjee
 * @version $Date: 2009-07-05 10:12:59 +0000 (Sun, 05 Jul 2009) $ $Id$
 */
public class DecoratedComment extends Comment implements CommentInterface, CreationInfoPersistable, Identifiable, Decoratable {


    private RenderEngine renderEngine;
    private Comment comment;

    public DecoratedComment(RenderEngine renderEngine, Comment comment) {
        this.renderEngine = renderEngine;
        this.comment = comment;
    }


    public String getContent() {
        return comment.getContent();
    }

    public void setContent(String content) {
        comment.setContent(content);
    }

    public Entry getEntry() {
        return comment.getEntry();
    }

    public void setEntry(Entry entry) {
        comment.setEntry(entry);
    }

    public void setCreationDate(Date creationDate) {
        comment.setCreationDate(creationDate);
    }

    public Date getCreationDate() {
        return comment.getCreationDate();
    }

    public void setCreator(User creator) {
        comment.setCreator(creator);
    }

    public User getCreator() {
        return comment.getCreator();
    }

    public long getId() {
        return comment.getId();
    }


    public String getDecoratedContent() {
        BaseRenderContext context = new BaseRenderContext();
        context.setParameters(new LinkedHashMap(){
            {
                put(BlogRenderEngine.RENDER_CONTEXT_ENTRY_ID_PARAM_KEY, comment.getEntry().getId());
            }
        });
        return renderEngine.render(getContent(), context);
    }
}
